#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QMessageBox>

Log::TextEditLog MainWindow::_logManager = Log::TextEditLog();

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
	ui->setupUi(this);

	_logManager.setWidget(ui->textEdit);

	if (!_server.listen(QHostAddress::Any, 666)) {
			QMessageBox::critical(this, tr("Threaded Fortune Server"),
					  tr("Unable to start the server: %1.")
					  .arg(_server.errorString()));
			close();
			return;
	}

	connect(ui->pushButton, SIGNAL(clicked()), SLOT(onBtn()));
}

MainWindow::~MainWindow()
{
	delete ui;
}

void MainWindow::addLogMsg(QString msg, Log::ILogManager::LogType type)
{
	qDebug() << msg;
	_logManager.addLogMessage(msg, type);
}

void MainWindow::onRecieveData(QByteArray msg)
{
	ui->textEdit->append(msg);
}

void MainWindow::onBtn()
{
	//_server.writeToClients("Server send data");
}
